package com.myebills.ebpsfrontend.cust.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Logoff the user by invalidation the user's session.
 */
public class EbppxLogoffServlet extends EbppxServlet {

    public EbppxLogoffServlet() {
    }

    protected void doRequest(HttpServletRequest req, HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException {
        // if a session doesn't exist, sessionPrev is null
        final HttpSession sessionPrev = req.getSession(false);
        if (null != sessionPrev) {
            try {
                sessionPrev.invalidate();
            } catch (IllegalStateException e) {
                // Do nothing (session was already invalidated).
            }
        }

        redirectToMappedUrl(req, res, EbppxConstants.URL_JSP_PARAM);
    }
}